RECT tabBar;
RECT navigator;
RECT page;
RECT windowRectSaved;
RECT ivMenu;
RECT ivClose;
RECT ivResize;
RECT ivMinimize;
RECT ivMaximize;
ULONG_PTR gdipToken;
BaseTab **tabs;
BaseTab *tabNow;
POINT cursorSaved;
int mouseDyn=0;
int derDraw=0;
int ivCloseDyn;
int ivClosePadding;
int ivOnHover=-1;
int ivMenuDyn=0;
int ivWarnColor=0x0000007f;
int navigatorBackgroundColor=0x00ffcc11;
int clickMaxOffset=3;
GpBitmap *ic_menu;
HICON ic_logo;
HPEN penForViews;
HBRUSH borderBrush;
HBRUSH backgroundBrush;
HBRUSH navigatorBrush;
HBRUSH ivWarnBrush;
LRESULT CALLBACK WndProc(HWND hwnd,UINT uint,WPARAM wParam,LPARAM lParam){
	static char traced=0;
	switch(uint){//不要太过相信这些动态传递了
	case WM_CLOSE:{
		DestroyWindow(hwnd);
		return 0;//block default behavior
	}
	case WM_CREATE:
		backgroundBrush=CreateSolidBrush(0x00ffffff);
		borderBrush=CreateSolidBrush(borderColor);
		ivWarnBrush=CreateSolidBrush(ivWarnColor);
		penForViews=CreatePen(PS_SOLID,2,0x00000000);
		navigatorBrush=CreateSolidBrush(navigatorBackgroundColor);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_ERASEBKGND:{
		PAINTSTRUCT ps;
		HDC hdc=BeginPaint(hwnd,&ps);
		RECT dirty=ps.rcPaint;
		FillRect(hdc,&dirty,backgroundBrush);
		RECT tmp;
		int nh=30,x,y,w,h;
		navigator.left=dirty.left;
		navigator.top=dirty.top;
		navigator.right=dirty.right;
		navigator.bottom=dirty.top+nh;
		ivMenu.left=navigator.left;
		ivMenu.top=navigator.top;
		ivMenu.right=navigator.left+nh;
		ivMenu.bottom=navigator.bottom;
		FillRect(hdc,&navigator,navigatorBrush);
		ivClose.left=navigator.right-nh;
		ivClose.top=navigator.top;
		ivClose.right=navigator.right;
		ivClose.bottom=navigator.bottom;
		HPEN oldPen=SelectObject(hdc,penForViews);
		ivClosePadding=nh/4;
		MoveToEx(hdc,ivClose.left+ivClosePadding,ivClose.top+ivClosePadding,NULL);
		LineTo(hdc,ivClose.right-ivClosePadding,ivClose.bottom-ivClosePadding);
		MoveToEx(hdc,ivClose.right-ivClosePadding,ivClose.top+ivClosePadding,NULL);
		LineTo(hdc,ivClose.left+ivClosePadding,ivClose.bottom-ivClosePadding);
		/*ivResize.left=ivClose.left-nh;
		ivResize.top=navigator.top;
		ivResize.right=ivClose.left;
		ivResize.bottom=navigator.bottom;*/
		//MoveToEx(hdc,ivResize.
		//FillRect(hdc,&logo,CreateSolidBrush(0x00138239));
		//DrawIconEx(hdc,logo.left,logo.top,ic_logo,nh,nh,0,NULL,DI_IMAGE);
		tabBar.left=dirty.left;
		tabBar.top=navigator.bottom;
		tabBar.right=dirty.right;
		tabBar.bottom=tabBar.top+30;
		//FillRect(hdc,&tabBar,CreateSolidBrush(0x009a98a8));
		page.left=dirty.left;
		page.top=tabBar.bottom;
		page.right=dirty.right;
		page.bottom=dirty.bottom;
		GpGraphics *gg;
		GdipCreateFromHDC(hdc,&gg);
		GdipSetPixelOffsetMode(gg,PixelOffsetModeHighQuality);
		GdipDrawImageRect(gg,ic_menu,0,0,nh,nh);
		//GdipGetImageWidth(ic_menu,&w);
		//GdipGetImageHeight(ic_menu,&h);
		//sprintf(msg,"bitmapWidth==%d,bitmapHeight==%d",w,h);
		//MessageBox(NULL,msg,"",0);
		if(tabNow){

		}else{
			FillRect(hdc,&page,CreateSolidBrush(0x0077c7de));
			SetBkMode(hdc,TRANSPARENT);
			tmp.left=page.left;
			tmp.top=page.top;
			tmp.right=page.right;
			tmp.bottom=page.top+30;
			DrawText(hdc,"start",5,&tmp,DT_CENTER);
		}
		/*FillRect(hdc,&(RECT){0,0,1,dirty.bottom},borderBrush);
		FillRect(hdc,&(RECT){0,0,dirty.right,1},borderBrush);
		FillRect(hdc,&(RECT){dirty.right-1,0,dirty.right,dirty.bottom},borderBrush);
		FillRect(hdc,&(RECT){0,dirty.bottom-1,dirty.right,dirty.bottom},borderBrush);*/
		GdipDeleteGraphics(gg);
		EndPaint(hwnd,&ps);
	}
	return 1;
	case WM_LBUTTONDOWN:{
		GetCursorPos(&cursorSaved);
		POINT cursorNow=cursorSaved;
		GetWindowRect(hwnd,&windowRectSaved);
		int xx=LOWORD(lParam);
		int yy=HIWORD(lParam);
		if(xx>=ivClose.left&&xx<ivClose.right&&yy>=ivClose.top&&yy<ivClose.bottom){
			ivCloseDyn=2;
		}else{//not a view has be click
			mouseDyn=1;
		}
	}
	break;
	case WM_LBUTTONUP:{
		POINT cursorNow;GetCursorPos(&cursorNow);
		int xx=LOWORD(lParam);
		int yy=HIWORD(lParam);
		int deltax=cursorNow.x-cursorSaved.x;
		int deltay=cursorNow.y-cursorSaved.y;
		if(xx>=ivClose.left&&xx<ivClose.right&&yy>=ivClose.top&&yy<ivClose.bottom){}else{
			if(ivCloseDyn==2){
				PostMessage(hwnd,WM_CLOSE,0,0);
			}
		}

		if(mouseDyn==1){mouseDyn=0;}
	}
	break;
	case WM_MOUSELEAVE:{
		traced=0;
		TRACKMOUSEEVENT tme={sizeof(tme),TME_CANCEL,hwnd};
		TrackMouseEvent(&tme);
		//MessageBox(NULL,"what fuck","",0);
		POINT cursorNow;
		GetCursorPos(&cursorNow);
		if(ivOnHover==0){
			int iw=ivMenu.right-ivMenu.left;
			int ih=ivMenu.bottom-ivMenu.top;
			HDC hdc=GetDC(hwnd);
			FillRect(hdc,&ivMenu,CreateSolidBrush(navigatorBackgroundColor));
			GpGraphics *gg;
			GdipCreateFromHDC(hdc,&gg);
			GdipSetPixelOffsetMode(gg,PixelOffsetModeHighQuality);
			GdipDrawImageRect(gg,ic_menu,ivMenu.left,ivMenu.top,iw,ih);
			GdipDeleteGraphics(gg);
			ReleaseDC(hwnd,hdc);
			RECT rcMenu;
			GetWindowRect(actionMenuWindow,&rcMenu);
			if(PtInRect(&rcMenu,cursorNow)){
				//ivMenuDyn=2;
			}else{
				ivMenuDyn=0;
				itemOnHover=-1;
				ShowWindow(actionMenuWindow,SW_HIDE);
			}
		}
	}
	break;
	case WM_MOUSEMOVE:{
		POINT cursorNow;
		GetCursorPos(&cursorNow);
		
		if(!traced){
			traced=1;
			TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT) };
			tme.dwFlags = TME_LEAVE;
			tme.hwndTrack = hwnd;
			TrackMouseEvent(&tme);
		}
		if(mouseDyn==1){
        	int deltax=cursorNow.x-cursorSaved.x;
			int deltay=cursorNow.y-cursorSaved.y;
			SetWindowPos(hwnd,NULL,windowRectSaved.left+deltax,windowRectSaved.top+deltay,0,0,SWP_NOREDRAW|SWP_NOSIZE);
		}else{	
			//ScreenToClient(hwnd,&cursorNow);
			int xx=LOWORD(lParam);
			int yy=HIWORD(lParam);
			POINT loc=cursorNow;
			ScreenToClient(hwnd,&loc);
			if(PtInRect(&ivMenu,loc)){
				if(ivOnHover!=0){
					HDC hdc=GetDC(hwnd);
					HDC layer=CreateCompatibleDC(hdc);
					int iw=ivMenu.right-ivMenu.left;
					int ih=ivMenu.bottom-ivMenu.top;
					HBITMAP hb=CreateCompatibleBitmap(hdc,iw,ih);
					// HBITMAP hb=CreateBitmap(iw,ih,1,32,NULL);
					SelectObject(layer,hb);
					BLENDFUNCTION blend = { AC_SRC_OVER, 0, 128, 0};//AC_SRC_ALPHA };
					HBRUSH hBrush = CreateSolidBrush(0x00121212);
					RECT dst={0,0,iw,ih};
					FillRect(layer,&dst, hBrush);
					AlphaBlend(hdc, ivMenu.left,ivMenu.top, iw, ih, layer, 0, 0, iw, ih, blend);
					DeleteObject(hBrush);
					DeleteObject(hb);
					DeleteDC(layer);
					ReleaseDC(hwnd,hdc);
					POINT ivp={ivMenu.left,ivMenu.bottom};
					ClientToScreen(hwnd,&ivp);
					SetWindowPos(actionMenuWindow,NULL,ivp.x,ivp.y,100,itemHeight*itemCount,SWP_NOZORDER);
					ShowWindow(actionMenuWindow,SW_SHOW);
				}
				if(ivOnHover==1){
					int iw=ivClose.right-ivClose.left;
					int ih=ivClose.bottom-ivClose.top;
					HDC hdc=GetDC(hwnd);
					FillRect(hdc,&ivClose,navigatorBrush);
					SelectObject(hdc,penForViews);
					MoveToEx(hdc,ivClose.left+ivClosePadding,ivClose.top+ivClosePadding,NULL);
					LineTo(hdc,ivClose.right-ivClosePadding,ivClose.bottom-ivClosePadding);
					MoveToEx(hdc,ivClose.right-ivClosePadding,ivClose.top+ivClosePadding,NULL);
					LineTo(hdc,ivClose.left+ivClosePadding,ivClose.bottom-ivClosePadding);
					ReleaseDC(hwnd,hdc);
					ivCloseDyn=0;
				}else if(ivOnHover==2){
				}
				ivOnHover=0;
			}else if(PtInRect(&ivClose,loc)){
				if(ivOnHover!=1){
					int iw=ivClose.right-ivClose.left;
					int ih=ivClose.bottom-ivClose.top;
					HDC hdc=GetDC(hwnd);
					FillRect(hdc,&ivClose,ivWarnBrush);
					SelectObject(hdc,penForViews);
					MoveToEx(hdc,ivClose.left+ivClosePadding,ivClose.top+ivClosePadding,NULL);
					LineTo(hdc,ivClose.right-ivClosePadding,ivClose.bottom-ivClosePadding);
					MoveToEx(hdc,ivClose.right-ivClosePadding,ivClose.top+ivClosePadding,NULL);
					LineTo(hdc,ivClose.left+ivClosePadding,ivClose.bottom-ivClosePadding);
					ReleaseDC(hwnd,hdc);
					//MessageBox(NULL,"what fuck!","",0);
				}
				if(ivCloseDyn==2){
					int dx=cursorNow.x-cursorSaved.x;
					int dy=cursorNow.y-cursorSaved.y;
				}
				if(ivOnHover==0){
					int iw=ivMenu.right-ivMenu.left;
					int ih=ivMenu.bottom-ivMenu.top;
					HDC hdc=GetDC(hwnd);
					FillRect(hdc,&ivMenu,CreateSolidBrush(navigatorBackgroundColor));
					GpGraphics *gg;
					GdipCreateFromHDC(hdc,&gg);
					GdipSetPixelOffsetMode(gg,PixelOffsetModeHighQuality);
					GdipDrawImageRect(gg,ic_menu,ivMenu.left,ivMenu.top,iw,ih);
					GdipDeleteGraphics(gg);
					ReleaseDC(hwnd,hdc);
					ShowWindow(actionMenuWindow,SW_HIDE);
					ivMenuDyn=0;
				}
				ivOnHover=1;
			}else if(ivOnHover==0){
				int iw=ivMenu.right-ivMenu.left;
				int ih=ivMenu.bottom-ivMenu.top;
				HDC hdc=GetDC(hwnd);
				FillRect(hdc,&ivMenu,CreateSolidBrush(navigatorBackgroundColor));
				GpGraphics *gg;
				GdipCreateFromHDC(hdc,&gg);
				GdipSetPixelOffsetMode(gg,PixelOffsetModeHighQuality);
				GdipDrawImageRect(gg,ic_menu,ivMenu.left,ivMenu.top,iw,ih);
				GdipDeleteGraphics(gg);
				ReleaseDC(hwnd,hdc);
				ShowWindow(actionMenuWindow,SW_HIDE);
				ivMenuDyn=0;
				ivOnHover=-1;
			}else if(ivOnHover==1){
				int iw=ivClose.right-ivClose.left;
				int ih=ivClose.bottom-ivClose.top;
				HDC hdc=GetDC(hwnd);
				FillRect(hdc,&ivClose,navigatorBrush);
				SelectObject(hdc,penForViews);
				MoveToEx(hdc,ivClose.left+ivClosePadding,ivClose.top+ivClosePadding,NULL);
				LineTo(hdc,ivClose.right-ivClosePadding,ivClose.bottom-ivClosePadding);
				MoveToEx(hdc,ivClose.right-ivClosePadding,ivClose.top+ivClosePadding,NULL);
				LineTo(hdc,ivClose.left+ivClosePadding,ivClose.bottom-ivClosePadding);
				ReleaseDC(hwnd,hdc);
				ivCloseDyn=0;
				ivOnHover=-1;
			}
			if(ivCloseDyn==2){
				if(PtInRect(&ivClose,loc)){
					int dx=cursorNow.x-cursorSaved.x;
					int dy=cursorNow.y-cursorSaved.y;
					if(abs(dx)>clickMaxOffset||abs(dy)>clickMaxOffset){
						ivCloseDyn=0;
					}
				}else{
					ivCloseDyn=0;
				}
			}else{
				
			}
		}
	}
	break;
	case WM_PAINT:{
		
	}
	break;
}
return DefWindowProc(hwnd,uint,wParam,lParam);
}